/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ftpcombiner.gui.applicationframe.framesplitter.filetable;

import ftpcombiner.filesystem.FileSystem;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Ben
 */
public class FileTableModel extends DefaultTableModel {

    private int oldRowCount;

    public FileTableModel() {
        oldRowCount = FileSystem.getInstance().getCurrentFiles().length+1;
    }

    @Override
    public int getColumnCount() {
        return 1;
    }

    @Override
    public int getRowCount() {
        return FileSystem.getInstance().getCurrentFiles().length + 1;
    }

    @Override
    public Object getValueAt(int row, int column) {
        if (row == 0) {
            return "Up...";
        } else {
            return FileSystem.getInstance().getCurrentFiles()[row - 1];
        }
    }

    public void update() {
        if(getRowCount()>oldRowCount){
            oldRowCount = getRowCount();
        }
        fireTableRowsUpdated(0, oldRowCount);
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                oldRowCount = getRowCount();
            }
        });
    }

    public void update(int index) {
        fireTableCellUpdated(index, 0);
    }
}